<%--
  Created by IntelliJ IDEA.
  User: 无
  Date: 2020/10/5
  Time: 10:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="utf-8"%>
<%@ page errorPage="error.jsp"%>

<!DOCTYPE html>
<html lang="zh-cmn-Hans">

<head>
    <meta charset="UTF-8">
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">
    <meta name="theme-color" content="#4285f4">
    <title>注册-智慧校园</title>
    <!-- css -->
    <link href="css/base.min.css" rel="stylesheet">
    <link href="css/project.min.css" rel="stylesheet">
    <link href="css/auth.css" rel="stylesheet">
    <link href="css/fonts.css" rel="stylesheet">
    <!-- js -->
    <script src="js/fk.js"></script>
</head>

<body class="page-brand">
<div class="authpage auth-reg">
    <div class="container">
        <section class="content-inner">
            <div class="auth-main auth-row">
                <div class="auth-top auth-row">
                    <a class="boardtop-left" href="index.jsp">
                        <div>首 页</div>
                    </a>
                    <div class="auth-logo">
                        <img src="images/authlogo.jpg" alt="">
                    </div>
                    <a href="login.jsp" class="boardtop-right">
                        <div>登 录</div>
                    </a>
                </div>
                <div class="rowtocol">
                    <div class="auth-row">
                        <div class="form-group-label auth-row">
                            <label class="floating-label" for="name">昵称</label>
                            <input class="form-control maxwidth-auth" id="name" type="text">
                        </div>
                    </div>
                </div>
                <div class="rowtocol">
                    <div class="auth-row">
                        <div class="form-group-label auth-row">
                            <label class="floating-label" for="email">邮箱(唯一凭证请认真对待)</label>
                            <input class="form-control maxwidth-auth" id="email" type="text" maxlength="32">
                        </div>
                    </div>
                </div>
                <div class="rowtocol">
                    <div class="auth-row">
                        <div class="form-group-label auth-row">
                            <label class="floating-label" for="passwd">密码</label>
                            <input class="form-control maxwidth-auth" id="passwd" type="password">
                            <p id="passwd-strong" style="text-align: left; margin: 3px; font-size: 80%"></p>
                        </div>
                    </div>
                </div>
                <div class="rowtocol">
                    <div class="auth-row">
                        <div class="form-group form-group-label">
                            <label class="floating-label" for="repasswd">重复密码</label>
                            <input class="form-control maxwidth-auth" id="repasswd" type="password">
                        </div>
                    </div>
                </div>

                <div class="rowtocol">
                    <div class="btn-auth auth-row">
                        <button id="reg" type="submit"
                                class="btn-reg btn btn-block btn-brand waves-attach waves-light">确认注册
                        </button>
                    </div>
                </div>
                <div class="auth-bottom auth-row auth-reg">
                    <div class="tgauth">
                        <p>注册即代表同意<a href="#">服务条款</a>，以及保证所录入信息的真实性，如有不实信息会导致账号被删除。</p>
                    </div>
                </div>

            </div>
        </section>
        <div class="card auth-tg">
            <div class="card-main">

            </div>
        </div>
    </div>
</div>


<div aria-hidden="true" class="modal modal-va-middle fade" id="tos_modal" role="dialog" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-heading">
                <h2 class="modal-title">注册 TOS</h2>
            </div>
            <div class="modal-inner">
                <ul>
                    <li>请提供真实邮箱，并自行保管。邮箱为用户的唯一凭证。</li>
                    <li>本站会加密存储用户密码，尽量保证数据安全，但并不保证这些信息的绝对安全。</li>
                    <li>禁止使用本站服务进行任何违法恶意活动。</li>
                    <li>使用任何节点，需遵循节点所属国家的相关法律以及中国法律。</li>
                    <li>禁止滥用本站提供的服务。</li>
                    <li>对于免费用户，我们有权在不通知的情况下删除账户。</li>
                    <li>任何违反使用条款的用户，我们将会删除违规账户并收回使用本站服务的权利。</li>
                </ul>
            </div>
            <div class="modal-footer">
                <p class="text-right">
                    <button class="btn btn-flat btn-brand-accent waves-attach waves-effect"
                            data-dismiss="modal" type="button" id="cancel">我不同意
                    </button>
                    <button class="btn btn-flat btn-brand-accent waves-attach waves-effect" data-dismiss="modal"
                            id="wu"
                            type="button">我同意
                    </button>
                </p>
            </div>
        </div>
    </div>
</div>


<div class="tiphidden"></div>


<div aria-hidden="true" class="modal modal-va-middle fade" id="result" role="dialog" tabindex="-1">
    <div class="modal-dialog modal-xs">
        <div class="modal-content">
            <div class="modal-inner">
                <p class="h5 margin-top-sm text-black-hint" id="msg"></p>
            </div>
            <div class="modal-footer">
                <p class="text-right">
                    <button class="btn btn-flat btn-brand-accent waves-attach" data-dismiss="modal" type="button"
                            id="result_ok">知道了
                    </button>
                </p>
            </div>
        </div>
    </div>
</div>

<footer class="ui-footer">
    <div class="container">
        &copy;2020 智慧校园卡 |
    </div>
</footer>

<!-- js -->
<script src="js/jquery-3.4.1.js"></script>
<script src="js/base.min.js"></script>
<script src="js/project.min.js"></script>

<script>
    $(document).ready(function () {
        function register() {
            code = 0;
            if ((getCookie('code')) !== '') {
                code = getCookie('code');
            }
            document.getElementById("reg").disabled = true;

            $.ajax({
                type: "POST",
                url: "",
                dataType: "json",
                data: {
                    email: $("#email").val(),
                    name: $("#name").val(),
                    passwd: $("#passwd").val(),
                    repasswd: $("#repasswd").val(),
                    code                    },
                success: (data) => {
                    if (data.ret === 1) {
                        $("#result").modal();
                        $$.getElementById('msg').innerHTML = data.msg;
                        window.setTimeout("location.href='login.jsp'", 1200);
                    } else {
                        $("#result").modal();
                        $$.getElementById('msg').innerHTML = data.msg;
                        setCookie('code', '', 0);
                        $("#code").val(getCookie('code'));
                        document.getElementById("reg").disabled = false;
                    }
                },
                error: (jqXHR) => {
                    $("#result").modal();
                    $$.getElementById('msg').innerHTML = `发生错误：${
                        jqXHR.status
                    }`;
                    document.getElementById("reg").disabled = false;
                }
            });
        }

        $("html").keydown(function (event) {
            if (event.keyCode === 13) {
                $("#tos_modal").modal();
            }
        });

        $("#reg").click(function () {
            register();
        });

    })
</script>



<script>
    function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] === variable) {
                return pair[1];
            }
        }
        return "";
    }

    function setCookie(cname, cvalue, exdays) {
        var d = new Date();
        d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
        var expires = "expires=" + d.toGMTString();
        document.cookie = cname + "=" + cvalue + "; " + expires;
    }

    function getCookie(cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i].trim();
            if (c.indexOf(name) === 0) return c.substring(name.length, c.length);
        }
        return "";
    }

    if (getQueryVariable('code') !== '') {
        setCookie('code', getQueryVariable('code'), 30);
        window.location.href = 'register.jsp';
    }

</script>

</body>
</html>



